package com.atguigu.gmall.order.consumer;


import com.atguigu.gmall.order.config.DeadLetterMqConfig;
import com.atguigu.gmall.order.service.OrderService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CancelOrderConsumer {

    @Autowired
    OrderService orderService;

    @RabbitListener(queues = DeadLetterMqConfig.queue_dead_2)
    public void cancelOrder(Long orderId, Message message, Channel channel){
        try {
            orderService.cancelOrder(orderId);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
